package com.amumu.netctoss.action;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import com.amumu.netctoss.dao.AccountDao;
import com.amumu.netctoss.dao.CostDao;
import com.amumu.netctoss.dao.ServiceDao;
import com.amumu.netctoss.entity.Account;
import com.amumu.netctoss.entity.Cost;
import com.amumu.netctoss.entity.Service;
/**
 *业务管理  
 */
public class ServiceAction extends BaseAction {
	@Resource
	private ServiceDao dao;
	@Resource
	private CostDao costDao;
	private List<Service> serviceList;
	private List<Cost> costList;
	private Service ser;
	private Map<String, Object> statusOptions;
	//要更新的状态
	private String status;
	//查询条件字段
	private String usernamesh;
	private String hostsh;
	private String idcardsh;
	private String statussh;
	
    //显示列表
	public String list() {
		try {
			statusOptions = dao.getStatusOptions();
			setPageCount(dao.getPageCount(PAGE_SIZE, 
					usernamesh, hostsh, idcardsh, statussh));
			serviceList = dao.search(page, PAGE_SIZE, usernamesh,hostsh, idcardsh, statussh);
			
			
		} catch (Exception e) {
			e.printStackTrace();
		}
		return SUCCESS;

	}
	
    //转到添加页面
	public String toAdd() {
		try {
			costList = costDao.findAll();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return SUCCESS;

	}

	//添加
	public String save() {
		try {
			dao.save(ser);
			ok = true;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return SUCCESS;

	}
	
	//加载修改页面
	public String load() {
		try {
			costList = costDao.findAll();
			ser = dao.findById(id);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return SUCCESS;

	}
	
    //修改
	public String update() {
		try {
			dao.update(ser);
			ok = true;
		} catch (Exception e) {
			ok = false;
			e.printStackTrace();
		}
		return SUCCESS;

	}
	
	//删除
	public String delete(){
		try {
			dao.delete(id);
			ok = true;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return SUCCESS;
	}
	
	//状态修改
	public String state() {
		try {
			dao.setStatus(id, status);
			ok = true;
		} catch (Exception e) {
			ok = false;
			e.printStackTrace();
		}
		return SUCCESS;

	}
	
    //查看详情
	public String detail() {
		try {
			statusOptions = dao.getStatusOptions();
			ser = dao.findById(id);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return SUCCESS;

	}
	
	//验证服务器存在
	public String vefifyHost(){
		try {
			System.out.println(ser.getUnixHost());
			if(ser!=null&&dao.hasHost(ser.getUnixHost())){
				ok = true;
			}else{
				ok = false;
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return SUCCESS;
	}
	
	
	// getter and setter
	public Service getSer() {
		return ser;
	}

	public void setSer(Service ser) {
		this.ser = ser;
	}

	public List<Service> getServiceList() {
		return serviceList;
	}

	public Map<String, Object> getStatusOptions() {
		return statusOptions;
	}
	public List<Cost> getCostList() {
		return costList;
	}
	public String getUsernamesh() {
		return usernamesh;
	}
	public void setUsernamesh(String usernamesh) {
		this.usernamesh = usernamesh.trim();
	}
	public String getHostsh() {
		return hostsh;
	}
	public void setHostsh(String hostsh) {
		this.hostsh = hostsh.trim();
	}
	public String getIdcardsh() {
		return idcardsh;
	}
	public void setIdcardsh(String idcardsh) {
		this.idcardsh = idcardsh.trim();
	}
	public String getStatussh() {
		return statussh;
	}
	public void setStatussh(String statussh) {
		this.statussh = statussh;
	}
	public void setStatus(String status) {
		this.status = status;
	}
	

}
